package br.com.projeto.teste;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import br.com.projeto.dao.hql.ActorDao;
import br.com.projeto.dao.hql.AddressDao;
import br.com.projeto.dao.hql.CategoryDao;
import br.com.projeto.dao.hql.CityDao;
import br.com.projeto.dao.hql.CountryDao;
import br.com.projeto.dao.hql.CustomerDao;
import br.com.projeto.dao.hql.FilmDao;
import br.com.projeto.dao.hql.FilmTextDao;
import br.com.projeto.dao.hql.InventoryDao;
import br.com.projeto.dao.hql.LanguageDao;
import br.com.projeto.dao.hql.PaymentDao;
import br.com.projeto.dao.hql.RentalDao;
import br.com.projeto.dao.hql.StaffDao;
import br.com.projeto.dao.hql.StoreDao;
import br.com.projeto.sakila.bean.TempoRelatorio;

public class ChamadaHibernate {
	
	TempoRelatorio tempoRelatorioJdbc;
	
	public TempoRelatorio iniciarConsulta(){
		
		tempoRelatorioJdbc = new TempoRelatorio();
		
		long tempoInicialSessionFactory = System.currentTimeMillis(); 
		
		SessionFactory sessionFactory;
		sessionFactory = new Configuration().configure("hibernate.cfg.xml")
				.buildSessionFactory();
		
		long tempoFinalSessionFactory = System.currentTimeMillis(); 
		long tempoSessionFactory = tempoFinalSessionFactory - tempoInicialSessionFactory;
		tempoRelatorioJdbc.setSessinFactory(tempoSessionFactory);
		
		ActorDao actorDao = new ActorDao(sessionFactory);
		tempoRelatorioJdbc.setActor(actorDao.buscarActor());

		
		AddressDao addressDao = new AddressDao(sessionFactory);
		tempoRelatorioJdbc.setAddress(addressDao.buscarAddress());

	
		CategoryDao categoryDao = new CategoryDao(sessionFactory);
		tempoRelatorioJdbc.setCategory(categoryDao.buscarCategory());

		
		CityDao cityDao = new CityDao(sessionFactory);
		tempoRelatorioJdbc.setCity(cityDao.buscarCity());

		
		CountryDao countryDao = new CountryDao(sessionFactory);
		tempoRelatorioJdbc.setCountry(countryDao.buscarActor());

		
		CustomerDao customerDao = new CustomerDao(sessionFactory);
		tempoRelatorioJdbc.setCustomer(customerDao.buscarCustomer());

		
		FilmDao filmDao = new FilmDao(sessionFactory);
		tempoRelatorioJdbc.setFilm(filmDao.buscarFilm());

		
		FilmTextDao filmTextDao = new FilmTextDao(sessionFactory);		
		tempoRelatorioJdbc.setFilmText(filmTextDao.buscarFilmText());

		
		InventoryDao inventoryDao = new InventoryDao(sessionFactory);
		tempoRelatorioJdbc.setInventory(inventoryDao.buscarInventory());

		
		LanguageDao languageDao = new LanguageDao(sessionFactory);
		tempoRelatorioJdbc.setLanguage(languageDao.buscarLanguage());

		
		PaymentDao paymentDao = new PaymentDao(sessionFactory);
		tempoRelatorioJdbc.setPayment(paymentDao.buscarPayment());

		
		RentalDao rentalDao = new RentalDao(sessionFactory);
		tempoRelatorioJdbc.setRental(rentalDao.buscarRental());

		
		StaffDao staffDao = new StaffDao(sessionFactory);
		tempoRelatorioJdbc.setStaff(staffDao.buscarStaff());

		
		StoreDao storeDao = new StoreDao(sessionFactory);
		tempoRelatorioJdbc.setStore(storeDao.buscarStore());
		
		sessionFactory.close();


		return tempoRelatorioJdbc;
	}

}
